home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 22.9 KB | 942 lines | [TEXT/KAHL] |
- /*
- File: SampleSMSAMServer.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __SAMPLESMSAMSERVER__
- #include "SampleSMSAMServer.h"
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __WRITELINEWINDOW__
- #include "WriteLineWindow.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #ifndef __DEBUGGINGMENUS__
- #include "DebuggingMenus.h"
- #endif
-
- #ifndef __VIRTUALFILE__
- #include "VirtualFile.h"
- #endif
-
- #ifndef __VIRTUALRAMORDISKFILE__
- #include "VirtualRamOrDiskFile.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __TRANSCRIPTWINDOW__
- #include "TranscriptWindow.h"
- #endif
-
- #ifndef __LOGWINDOW__
- #include "LogWindow.h"
- #endif
-
- #ifndef __2020TOCONNECTORGATEWAY__
- // #include "2020toConnectorGateway.h"
- #endif
-
- #ifndef __ATOBMAILGATEWAY__
- #include "AtoBMailGateway.h"
- #endif
-
- #ifndef __2020HALFGATEWAY__
- #include "2020HalfGateway.h"
- #endif
-
- #ifndef __HFSHALFGATEWAY__
- #include "HFSHalfGateway.h"
- #endif
-
- #ifndef __CONNECTORHALFGATEWAY__
- // #include "ConnectorHalfGateway.h"
- #endif
-
- // #ifndef __PAGERHALFGATEWAY__
- // #include "PagerHalfGateway.h"
- // #endif
-
- #ifndef __CONNECTIONS__
- #include <Connections.h>
- #endif
-
- #ifndef __COMMRESOURCES__
- #include <CommResources.h>
- #endif
-
- #ifndef __FILETRANSFERS__
- #include <FileTransfers.h>
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __STATUSMONITOR__
- #include "StatusMonitor.h"
- #endif
-
- #ifndef __STATUSDATABASE__
- #include "StatusDatabase.h"
- #endif
-
- #ifndef __GATEWAYCONFIG__
- #include "GatewayConfig.h"
- #endif
-
- #ifndef __LETTERLOG__
- #include "LetterLog.h"
- #endif
-
- #ifndef __BOVINECONSTANTS__
- #include "BovineConstants.h"
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __FILESPEC__
- #include "FileSpec.h"
- #endif
-
- #ifndef __DEBUGGINGWINDOWS__
- #include "DebuggingWindows.h"
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STATUSWINDOW__
- #include "StatusWindow.h"
- #endif
-
- #ifndef __EVENTTIMER__
- #include "EventTimer.h"
- #endif
-
- #ifndef __THREADCLASSES__
- #include "ThreadClasses.h"
- #endif
-
- /***********************************|****************************************/
-
- //#define DefaultStackSize() *((long *)DefltStack)
- //#define StackBase() *((Ptr *)CurStackBase)
-
- Boolean gReadyToQuit; // this gets set to true when all of the threads have
- Boolean gPausing = false; // responded to the "we're quitting" flag
- Boolean gInBackground = false; // Assume we start execution in the foreground
-
- TMailGateway* gMailGateway = nil;
- TStatusMonitor* gStatusMonitor = nil;
- Boolean gStartedThreads = false;
- short gBovineWorkingVRefNum, gBovineTempVRefNum;
- long gBovineWorkingDirID, gBovineTempDirID, gBovineLogDirID;
-
- extern unsigned short gCurrentGatewayNumber;
- // extern void DebugDisposeCCLEngine();
- extern pascal void WWFlushOutputFile();
-
- void CreateMainApplicationThread();
-
- short gBovineServerPrefsFile ; //default initialization to zero
- short gApplicationFile ; //default initialization to zero
- TStatusWindow * gStatusWindow = nil;
-
- /***********************************|****************************************/
-
- #define cAppleEventReply 40 // General command number used to process
- #define cFinderNew 41 // AppleEvent 'oapp'
- #define cFinderPrint 42 // AppleEvent 'pdoc'
- #define cFinderOpen 43 // AppleEvent 'odoc'
- #define cFinderQuit 44 // AppleEvent 'quit'
-
- /***********************************|****************************************/
-
- Boolean IsGatewayPausing ( )
- {
- return gPausing;
- }
-
- /***********************************|****************************************/
-
- void SetGatewayPausing ( Boolean pause )
- {
- if ( IsGatewayPausing ( ) )
- {
- gPausing = false;
- if ( gStatusWindow )
- gStatusWindow->SetButtonTitle ( 1, "\pPause");
- }
- else
- {
- gPausing = true;
- if ( gStatusWindow )
- gStatusWindow->SetButtonTitle ( 1, "\pResume");
- }
- }
-
- /***********************************|****************************************/
-
- void QuitGateway ( )
- {
- gReadyToQuit = true;
- }
-
- /***********************************|****************************************/
- /*pascal OSErr AppleEventsDispatch ( const AppleEvent& message, const AppleEvent& reply, long info )*/
-
- pascal OSErr AppleEventsDispatch ( const AppleEvent* message, const AppleEvent* reply, long info )
- {
- switch (info)
- {
- case cStatusLogInit:
- case cItemsToBeMonitored:
- case cStopMonitoring:
- case cStatusSessionAlive:
- case cMonitorCommand:
- case cGetConfigCommand:
- case cSetConfigCommand:
- if ( gStatusMonitor )
- gStatusMonitor->HandleAppleEvents(*message, *reply, info);
- break;
-
- case cFinderNew:
- case cFinderOpen: // We don't open 'documents' per se, so ignore odocs and pdocs
- case cFinderPrint:
- break;
-
- case cFinderQuit:
- gReadyToQuit = true;
- break;
-
- default:
- #if debug
- if (steveFlag.Flag(6))
- steve << "AppleEvent not handled by DispatchAppleEvent!! " << info << endl;
- #endif
- break;
- }
-
- return noErr;
- }
-
- /***********************************|****************************************/
-
- void HandleHighLevelEvent(EventRecord* event)
- { extern T2020HalfGateway* g2020HalfGateway;
-
- OSErr theErr = noErr;
- if ( g2020HalfGateway && g2020HalfGateway->HandleAppleMailHighLevelEvent ( *event ) )
- ; // An AOCE High Level event; so ignore it.
- else
- theErr = AEProcessAppleEvent(event);
-
- #if debug
- if ( theErr == noErr )
- {
- return;
- }
- else if (theErr == errAEEventNotHandled)
- {
- if (steveFlag.Flag(6))
- steve << "BovineServer::Did not handle the Apple Event - AEEventNotHandled" << endl;
- }
- else
- {
- if (steveFlag.Flag(6))
- steve << "BovineServer::Error handling apple event :" << theErr << endl;
- }
- #endif
- }
-
- /***********************************|****************************************/
-
- void DoEvent(EventRecord*event)
- {
- if ( TTranscriptWindow::IsLogWindowEvent ( *event ) )
- return;
-
- if ( TLogWindow::IsLogWindowEvent ( *event ) )
- return;
-
- // if (HandleDebuggingWindowsEvent(event))
- // return;
-
- if ( HandleDebuggingMenuEvent ( event ) )
- return;
-
- if ( TDialogWindow::HandleAnEvent ( *event ) )
- return;
-
- // Figure out what type of event it is, and what to do about it
- switch ( event->what )
- {
- case nullEvent:
- break;
-
- case osEvt:
- switch (event->message >> 24)
- {
- case suspendResumeMessage:
- // If we're resuming, then restore the cursor to the arrow
- gInBackground = ( (event->message & 0x01) != resumeFlag );
- if ( !gInBackground )
- InitCursor();
- break;
- }
- break;
-
- case kHighLevelEvent:
- #if debug
- if (steveFlag.Flag(6))
- {
- keith << "main: Incoming AppleEvent of type "; OutputOSType(keith, OSType(event->message));
- keith << " "; OutputOSType(keith, OSType(* (long *) &event->where)); keith << endl;
- }
- #endif
- HandleHighLevelEvent(event);
- break;
- }
- }
-
- /***********************************|****************************************/
-
- #pragma segment Main
- void SendLogToStatusMonitor(long tupleID, char* theMsg)
- {
- if (gStatusMonitor != nil)
- {
- #if debug
- if (steveFlag.Flag(3))
- steve << "Forcing update to status monitor!" << endl;
- #endif
- gStatusMonitor->UpdateLog(tupleID, theMsg);
- }
- }
-
- /***********************************|****************************************/
-
- #if debug
- #pragma segment MiscDebugOnly
- #endif
-
- Boolean GetAutostartOption()
- {
- FInfo finderInfo;
- return HGetFInfo(gBovineWorkingVRefNum, gBovineWorkingDirID, k2020ServerAutoStartFile, &finderInfo) == noErr;
- }
-
- /***********************************|****************************************/
-
- void
- ToggleAutostartOption()
- {
- if ( GetAutostartOption() )
- HDelete(gBovineWorkingVRefNum, gBovineWorkingDirID, k2020ServerAutoStartFile);
- else
- HCreate(gBovineWorkingVRefNum, gBovineWorkingDirID, k2020ServerAutoStartFile,'\?\?\?\?', '\?\?\?\?');
- }
-
- /***********************************|****************************************/
-
- void
- SetNewGlobalGateway ( TMailGateway* newGateway, const char* serverName = nil )
- {
- delete gMailGateway;
- gMailGateway = newGateway;
-
- // Set up the status monitor.
- gStatusMonitor = new TStatusMonitor ( gMailGateway );
- if (gStatusMonitor)
- gStatusMonitor->Run();
-
- if ( !gMailGateway )
- return;
- else if ( !serverName )
- return;
- else if ( gMailGateway->Setup ( gBovineWorkingVRefNum, gBovineWorkingDirID, serverName ) )
- gMailGateway->Run ();
- else
- SetNewGlobalGateway ( nil );
-
-
- keith << "main: " << serverName << ".Setup()" << endl;
- }
-
- /***********************************|****************************************/
-
- Boolean gMailGatewayShuttingDown = false;
-
- /***********************************|****************************************/
-
- Boolean ShutDownGateway ( )
- {
- Boolean result = false;
-
- if ( gMailGateway )
- {
- keithDB ( "BovineServer::ShutDownGateway(), beginning shutdown process." );
- gMailGatewayShuttingDown = true;
- result = gMailGateway->PrepareToShutDown ( 60 );
- }
-
- return result;
- }
-
- /***********************************|****************************************/
-
- void
- SetupAtoBGateway ( THalfGateway* a, THalfGateway* b, const char* serverName )
- {
- SetNewGlobalGateway ( new TAtoBMailGateway ( a, b, gBovineWorkingVRefNum, gBovineWorkingDirID ), serverName );
- }
-
- /***********************************|****************************************/
-
- void
- CreateMailGatewayNWrapper(unsigned long gatewayToCreate, unsigned long )
- {
- switch (gatewayToCreate)
- {
- case k2020ConnectorItem:
- break;
-
- case k2020HFSItem:
- SetupAtoBGateway ( new T2020HalfGateway, new THFSHalfGateway, "2020∞HFSMailA" );
- break;
-
- case kHFSConnectorItem:
- break;
-
- case kATSHFSItem:
- SysBeep ( 10 );
- break;
-
- case kHFSPagerItem:
- break;
-
- case kHFSHFSItem:
- SetupAtoBGateway ( new THFSHalfGateway, new THFSHalfGateway, "HFSMailA∞HFSMailB" );
- break;
-
- default:
- SetNewGlobalGateway ( nil );
- break;
- }
-
- gCurrentGatewayNumber = gMailGateway ? (unsigned short) gatewayToCreate : 0;
- }
-
- /***********************************|****************************************/
-
- void CreateMailGatewayN(short n)
- {
- // CreateMailGatewayNWrapper ( n, 0 );
- createThread('STAR', (FNULUL) CreateMailGatewayNWrapper, 32 * 1024, n, 0, TNormalMode );
- }
-
- /***********************************|****************************************/
-
- //
- // This function will try to kill the thread manager and then exit from the application.
- // It is designed to be used from Macsbug, by typing g exitApp
- //
-
- #pragma segment Main
- extern "C"
- {
- void exitApp ()
- {
- SetA5( *(long*) LMGetCurrentA5() );
- WWFlushOutputFile();
-
- /// Try to kill the thread manager. With luck, it'll work.
- if (gStartedThreads)
- {
- #ifndef newThreads
- endThreadMgr();
- #endif
-
- gStartedThreads = false;
- }
-
- ExitToShell();
- }
- }
-
- /***********************************|****************************************/
-
- void PauseIfDiskSpaceIsLow()
- {
- const unsigned long kLowLimit = 2097152; // At least 2 Meg
- const unsigned long kOneMeg = 1048576; // At least 2 Meg
-
- Str31 volName;
- short vRefNum;
- long freeBytes;
- short drvNum = -1;
- OSErr err = GetVInfo (drvNum,(StringPtr) &volName, &vRefNum,&freeBytes);
-
- if ( (err == noErr) && (freeBytes < kLowLimit))
- {
- if ( ! IsGatewayPausing () ) {
- steve << date << " " << time << "Pausing gateway because '" << volName << "' is low on free space." << endl;
- SetGatewayPausing ( true );
- }
- }
- }
-
- /***********************************|****************************************/
-
- #pragma segment Main
-
- Boolean CheckMemoryStatus (Boolean onlyPrintIfChanged = true, Boolean verbose = false, Boolean forcePurge = false)
- {
- long growSize;
- long freeMem = FreeMem();
- long largestBlock = MaxMem(&growSize);
- Boolean result = false;
- static long gCheckMemoryStatusSavedFreeMemAmount = 0;
-
- if (((onlyPrintIfChanged == false) || (gCheckMemoryStatusSavedFreeMemAmount != freeMem)) &&
- (verbose || (freeMem <= 65536) || (largestBlock < 32768)))
- {
- keith << time << "Free memory:" << freeMem << " ";
-
- if (forcePurge)
- {
- PurgeMem(maxSize);
- keith << "(" << FreeMem() << "after purge) ";
- }
-
- largestBlock = MaxMem(&growSize);
- keith << " LargestBlock:" << largestBlock << endl;
- result = true;
- }
-
- return result;
- }
-
- /***********************************|****************************************/
-
- unsigned long GetDateTimeF ( )
- {
- unsigned long result;
- GetDateTime ( & result );
-
- return result;
- }
-
- /***********************************|****************************************/
-
- unsigned long gGatewayLoadIndicator [ 16 ] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
-
- /***********************************|****************************************/
-
- Boolean ThreadWaitNextEvent ( short eventMask, EventRecord* event, RgnHandle mouseRgn )
- {
- TEventTimer timeOurThreadsAreTaking, timeOurThreadsPlusWaitNextEventTakes;
- Boolean result = false;
-
- EventAvail ( eventMask, event );
- if ( event->what == nullEvent )
- {
- TThreadManagerThread::WakeUpSleepingThreadsTask ();
-
- timeOurThreadsAreTaking.Start();
- timeOurThreadsPlusWaitNextEventTakes.Start();
-
- // Now, let all of our threads run.
- TThread::YieldCurrentThread ();
-
- timeOurThreadsAreTaking.Stop ();
-
- unsigned long timeToSleep = 15;
- result = WaitNextEvent ( eventMask, event, timeToSleep, mouseRgn );
-
- timeOurThreadsPlusWaitNextEventTakes.Stop();
-
- // Now, store the time we consumed in the array indicators. This is a 16 second, revolving
- // array of how many microseconds we used during the previous 16 seconds of real time.
- unsigned long seconds = ( GetDateTimeF () & 0x0000000f );
- gGatewayLoadIndicator[ seconds ] += timeOurThreadsAreTaking.GetElapsedTimeInMicroseconds ();
- gGatewayLoadIndicator[ ( seconds + 1 ) & 0x0000000f ] = 0;
-
- #if 0
- short percentOfTimeConsumedByUs = ( ( 100 * timeOurThreadsAreTaking.GetElapsedTimeInMicroseconds() ) / timeOurThreadsPlusWaitNextEventTakes.GetElapsedTimeInMicroseconds () );
-
- keith << "ThreadWaitNextEvent::load=";
- keith << GetCurrentServerLoad() << " % we used = " << percentOfTimeConsumedByUs << "% " <<
- timeOurThreadsAreTaking.GetElapsedTimeInMicroseconds() << " of " <<
- timeOurThreadsPlusWaitNextEventTakes.GetElapsedTimeInMicroseconds() << endl;
-
- #endif
- }
- else
- {
- unsigned long timeToSleep = 15;
- result = WaitNextEvent ( eventMask, event, timeToSleep, mouseRgn );
- }
-
- return result;
- }
-
- /***********************************|****************************************/
-
- unsigned long GetCurrentServerLoad ( )
- {
- unsigned long result = 0;
- for ( unsigned long i = 0; i < 16; i ++ )
- result += gGatewayLoadIndicator [ i ];
- result = between ( result / ( 16 * 10000 ), 0, 100 ); // make it into a percent used
-
- return result;
- }
-
- /***********************************|****************************************/
-
- #pragma segment Initialize
-
- void SetUpVirtualFiles ()
- {
- // Create Bovine Temp folder. Temporary items are kept in this folder.
- gBovineTempDirID = CreateFolderIfItDoesntExist(gBovineWorkingVRefNum, gBovineWorkingDirID, "\pBovineTemp");
- DeleteFilesInFolder(gBovineTempVRefNum, gBovineTempDirID);
-
- FSSpec spec;
- spec.vRefNum = gBovineWorkingVRefNum;
- spec.parID = gBovineTempDirID;
- TVirtualRamOrDiskFile::SetDefaultStorageLocation (spec);
-
- // Create Bovine Logs
- gBovineLogDirID = CreateFolderIfItDoesntExist(gBovineWorkingVRefNum, gBovineWorkingDirID, "\pBovine Logs");
- gBovineLetterLog = new TLetterLog ( TFileSpec ( gBovineWorkingVRefNum, gBovineLogDirID, "\pLetterLog" ) );
- gBovineLetterLog->Open ();
- }
-
- /***********************************|****************************************/
-
- short OpenApplicationPreferencesFile ( )
- {
- // The preferences file should be called "<Application Name> Prefs".
- /* CStr255 prefsFileName = * (StringPtr) 0x910 + "\p Prefs";*/
- Str255 prefsFileName = * (StringPtr) 0x910 + "\p Prefs";
- short result = -1;
-
- short prefsVRefNum;
- long prefsDirID;
-
- /* first-time escapade, get refnum for application if we don't have it already */
-
- if ( !gApplicationFile && !gBovineServerPrefsFile )
- gApplicationFile = CurResFile();
-
- if ( FindFolder ( kOnSystemDisk, kPreferencesFolderType, kCreateFolder, & prefsVRefNum, & prefsDirID) == noErr ) {
- HCreate ( prefsVRefNum, prefsDirID, prefsFileName, 'BLoJ', 'pref' );
- HCreateResFile ( prefsVRefNum, prefsDirID, prefsFileName );
- result = HOpenResFile ( prefsVRefNum, prefsDirID, prefsFileName, fsRdWrPerm );
- if ( result > 0 )
- {
- UseResFile ( result ); //make it the current resource file if it was already open
- }
- }
-
- return result;
- }
-
- /***********************************|****************************************/
-
- #pragma segment Initialize
- extern Boolean gBovineServerWasInitialized;
- extern void SetNewHandler ();
-
- #include <New.h>
-
- void BreakStr ( const Str255 str );
-
- void InitializeApp()
- {
- SetApplLimit((Ptr) ((long) LMGetCurStackBase() - min(LMGetDefltStack(), 0x4000)));
- MaxApplZone(); /* expand the heap so code segments load at the top */
-
- for ( short moreMastersIndex = 40; moreMastersIndex >= 0; moreMastersIndex-- )
- MoreMasters();
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- // Get current directory and volume
- WDPBRec paramBlock;
- paramBlock.ioNamePtr = nil;
- OSErr err = PBHGetVol(¶mBlock,false);
- long dRefNum = paramBlock.ioWDDirID;
- gBovineWorkingVRefNum = gBovineTempVRefNum = paramBlock.ioWDVRefNum;
-
- // Set res file reference of the application file
- // gApplicationFile = CurResFile(); now done in OpenApplicationPreferencesFile()
-
- // Create the Bovine Working directory, which will form the 'top' of a tree below which
- // all of the different gateway and half gateway modules will use to store configuration
- // information, data files, etc.
- //
- gBovineWorkingDirID = CreateFolderIfItDoesntExist(gBovineWorkingVRefNum, dRefNum, "\pBovine Working");
-
- // Open up the preferences file, creating one if it does not already exist.
- // This is normally done as part of DebugFlag init
- if ( gBovineServerPrefsFile == 0 )
- gBovineServerPrefsFile = OpenApplicationPreferencesFile();
-
- SetNewHandler();
-
- #ifndef newThreads
- initThreadMgr (true);
- #else
- // Verify that the threads manager is installed.
- long value;
- if ( ( Gestalt ( gestaltThreadMgrAttr, &value ) != noErr ) || ( value & ( 1 << gestaltThreadMgrPresent) == 0 ) )
- {
- #if debug
- DebugStr ("\p The Threads Manager extension must be installed to use this gateway." );
- #endif
-
- ExitToShell();
- }
-
- CreateMainApplicationThread();
- #endif
-
- gReadyToQuit = false;
- SetGatewayPausing ( false );
- gStartedThreads = true;
-
- #ifndef newThreads
- TSetRefCon('MAIN');
- TSetWNESleep(24);
- #endif
-
- InitializeDebuggingWindows();
- void ShowThreadStatusDialog ( );
- // ShowThreadStatusDialog();
-
- gBovineServerWasInitialized = true;
-
- addressTypesFlag.SetFlag ( 1 );
- addressTypesFlag.SetFlag ( 2 );
- addressTypesFlag.SetFlag ( 3 );
- addressTypesFlag.SetFlag ( 4 );
- addressTypesFlag.SetFlag ( 8 );
- addressTypesFlag.SetFlag ( 9 );
- addressTypesFlag.SetFlag ( 10 );
- addressTypesFlag.SetFlag ( 11 );
- addressTypesFlag.SetFlag ( 12 );
- addressTypesFlag.SetFlag ( 13 );
-
- // Set up the debugging environment...
- InitializeDebuggingMenus();
-
- // Initialize the various communications toolbox routines.
- {
- OSErr err = InitCRM();
- if (err)
- keith << "main: InitCRM() returned " << err << endl;
-
- err = InitCM();
- if (err )
- keith << "main: InitCM() returned " << err << endl;
- err = InitFT();
- if (err)
- keith << "main: InitFT() returned " << err << endl;
- }
-
-
- // If we don't have enough heap space or memory, complain
- { long available = (long) GetApplLimit() - (long) ApplicZone();
-
- if ( available < kMinHeap )
- {
- Str255 buffer;
- sprintf ((char *) &buffer[0], "*** BovineServer needs %d bytes in the heap -- only %d are available.", kMinHeap, available);
-
- buffer[0] = strlen((char *) &buffer[0]);
- BreakStr (buffer);
- }
- }
-
- InitUAppleEvents((ProcPtr) &AppleEventsDispatch);
-
- {
- long total, contig;
- PurgeSpace(&total, &contig);
- if (total < kMinSpace)
- {
- Str255 buffer;
- sprintf ((char *) &buffer[0], "*** BovineServer needs %d bytes in the memory -- only %d are available.",
- kMinSpace, total);
- buffer[0] = strlen((char *) &buffer[0]);
- BreakStr (buffer);
- }
- }
-
- gStatusWindow = new TStatusWindow ( 2000, 2000, & GetCurrentServerLoad );
- gStatusWindow->ShowWindow ();
-
- SetUpVirtualFiles ();
-
- #if debug
- if (GetAutostartOption())
- {
- keith << "Startup: Autostart option active, instantiating default gateway." << endl;
- CreateMailGatewayN(1);
- gCurrentGatewayNumber = gMailGateway ? 1 : 0;
- SetGatewayPausing ( false );
- }
- #else
- CreateMailGatewayN(1);
- gCurrentGatewayNumber = gMailGateway ? 1 : 0;
- #endif
- }
-
- /***********************************|****************************************/
-
- #pragma segment Main
-
- #ifdef newThreads
- Boolean TWaitNextEvent ( long eventMask, EventRecord* eventRecord, RgnHandle rgn )
- {
- TYield();
- return WaitNextEvent ( eventMask, eventRecord, (gInBackground) ? 30 : 5, rgn );
- }
- #endif
-
- int main ()
- {
- // Hold down the mouse button to skip execution of the program
- if (Button())
- exitApp();
-
- InitializeApp(); /* initialize the program */
- // UnloadSeg( _DataInit); /* note that _DataInit must not be in Main! */
- // UnloadSeg((Ptr) Initialize); /* note that Initialize must not be in Main! */
-
- EventRecord event;
-
- do
- {
- // Update the 'time' in the gateway status window.
- if ( gStatusWindow )
- {
- Str255 timeString;
- unsigned long currentTime;
- static unsigned long gStatusWindowTimeLastUpdate = 0;
-
- GetDateTime ( & currentTime );
-
- if ( currentTime != gStatusWindowTimeLastUpdate )
- {
- IUTimeString ( currentTime, true, timeString );
- gStatusWindow->SetTextItem ( 5, timeString );
- gStatusWindowTimeLastUpdate = currentTime;
- }
- }
-
- if ( IsGatewayPausing () )
- {
- if (WaitNextEvent (everyEvent, &event, 5, nil) )
- DoEvent (&event);
- }
- else if ( ThreadWaitNextEvent (everyEvent, &event, nil) )
- DoEvent (&event);
- else
- TDialogWindow::HandleAnEvent ( event );
-
- if ( gStatusWindow )
- gStatusWindow->UpdateLoadIndicator ();
-
- FlushDebugBuffers ();
-
- CheckMemoryStatus(true, false, false);
- PauseIfDiskSpaceIsLow();
-
- // If the gateway is in the process of 'shutting down', then
- // check whether it has finished. If so, then quit.
- if ( gMailGatewayShuttingDown )
- if ( gMailGateway && gMailGateway->ReadyToShutDown ( ) )
- {
- gReadyToQuit = gMailGateway->ShutDown ();
-
- keith << "main:: After shutdown, thread status is:" << endl;
- extern void ShowAllThreadStatus ( ostream& );
- ShowAllThreadStatus( keith );
- }
- }
- while ( !gReadyToQuit );
-
- keith << "main: Quitting…, gReadyToQuit = true" << endl << flush;
-
- #if debug
- // DebugDisposeCCLEngine();
- #endif
-
- delete gMailGateway;
- delete gBovineLetterLog;
-
- keith << "Quitting gateway! " << time << endl << flush;
- #ifndef newThreads
- endThreadMgr();
- #endif
-
- FlushDebugBuffers ();
-
- unsigned long stopTime = (unsigned long) TickCount () + 90;
- while ( TickCount() < stopTime ) ;
-
- void HideThreadStatusDialog ();
- HideThreadStatusDialog ();
-
- CloseResFile ( gBovineServerPrefsFile );
- gBovineServerPrefsFile = -1;
-
- return noErr;
- }
-
-
-